package cn.zjutleo.village_server.controller;

import cn.zjutleo.village_server.annotation.RequiresLogin;
import cn.zjutleo.village_server.dto.TenantInfoDto;
import cn.zjutleo.village_server.exception.apiException.daoException.SelectException;
import cn.zjutleo.village_server.service.TenantService;
import cn.zjutleo.village_server.util.ThreadLocalUtil;
import cn.zjutleo.village_server.vo.ResponseBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author : Qin Zhenghan
 * @date : Created in 2021/9/25
 * @description: 租客相关控制类
 */
@Api(tags = "租客相关控制类")
@RestController
@RequestMapping("/tenant")
public class TenantController {

    @Resource
    private TenantService tenantService;

    @ApiOperation("添加租客信息")
    @RequiresLogin
    @PostMapping("/add")
    public ResponseBean<Object> addTenantInfo(@RequestBody TenantInfoDto tenantInfoDto) throws SelectException {
        Integer userId = ThreadLocalUtil.getCurrentUser();
        tenantService.addTenantInfo(tenantInfoDto, userId);
        return new ResponseBean<>(null);
    }

    @ApiOperation("更新租客信息")
    @RequiresLogin
    @PutMapping("/update")
    public ResponseBean<Object> updateTenantInfo(@RequestBody TenantInfoDto tenantInfoDto) throws SelectException {
        Integer userId = ThreadLocalUtil.getCurrentUser();
        tenantService.updateTenantInfo(tenantInfoDto, userId);
        return new ResponseBean<>(null);
    }
}
